package com.sojpt.boot.controller.business;

import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import com.sojpt.boot.ui.iview.IViewController;
import com.sojpt.kit.SoJLogKit;
import com.sojpt.model.DicPopedom;
import com.sojpt.model.LkyApplyRecord;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Description: 本类用于逾期申请表(总管理)
 * Created by SMW on 2020/2/17 12:31
 */
@RestController
@RequestMapping("/admin/applyAdmin/")
public class LkyApplyAdministrationController extends IViewController {

    @GetMapping("list")
    public void list() {

        Map<String,String> map =new HashMap<>();
        map.put("mid",getPara("mid"));
        map.put("coid",getPara("coid"));
        map.put("mid",getPara("mid"));
        map.put("uid",getPara("uid"));
        LkyApplyRecord lkyApplyRecord  = getModel(LkyApplyRecord.class,"lkyApplyRecord");
        SqlPara sqlPara = Db.getSqlPara("lky_apply_admin.select", map);
        Page<Record> page = Db.paginate(pageNumber(), pageSize(), sqlPara);
        renderJson(page);
    }

    @PostMapping("update")
    public void update(){
        DicPopedom dicPopedom = new DicPopedom();
        dicPopedom.setForwardAction("/admin/applyAdmin/update");
        LkyApplyRecord lkyApplyRecord = getModel(LkyApplyRecord.class,"lkyApplyRecord");
        lkyApplyRecord.setStaute(1);
        lkyApplyRecord.setPassTime(new Date());
        if (lkyApplyRecord.update()){
            renderJson(Ret.ok());
            dicPopedom.setPopedomName("修改成功");
        } else {
            renderJson(Ret.fail());
            dicPopedom.setPopedomName("修改失败");
        }
        SoJLogKit.writeLog(this, dicPopedom,getSessionUser());
    }

    @PostMapping("updateS")
    public void updateS(){
        DicPopedom dicPopedom = new DicPopedom();
        dicPopedom.setForwardAction("/admin/applyAdmin/updateS");
        LkyApplyRecord lkyApplyRecord = getModel(LkyApplyRecord.class,"lkyApplyRecord");
        lkyApplyRecord.setStaute(2);
        if (lkyApplyRecord.update()){
            renderJson(Ret.ok());
            dicPopedom.setPopedomName("修改成功");
        } else {
            renderJson(Ret.fail());
            dicPopedom.setPopedomName("修改失败");
        }
        SoJLogKit.writeLog(this, dicPopedom,getSessionUser());
    }
}
